# # Ejemplo de creacion de hoja Excel
# import xlwt
# from datetime import datetime
# style0 = xlwt.easyxf('font: name Times New Roman, colour red, bold on')
# style1 = xlwt.easyxf('',num_format_str='DD-MMM-YY')
# wb = xlwt.Workbook()
# ws = wb.add_sheet('A Test Sheet',cell_overwrite_ok=True)
# ws.write(0, 0, 'Test', style0)
# ws.write(1, 0, datetime.now(), style1)
# ws.write(2, 0, 4)
# ws.write(2, 1, 1)
# ws.write(2, 2, xlwt.Formula("A3+B3"))
# wb.save('example.xls')


# # Ejemplo de lectura de hoja Excel
# import xlrd
# book = xlrd.open_workbook("example.xls")
# print "The number of worksheets is", book.nsheets
# print "Worksheet name(s):", book.sheet_names()
# sh = book.sheet_by_index(0)
# print sh.name, sh.nrows, sh.ncols
# print "Cell (2,0) is: ", sh.cell_value(rowx=2, colx=0)
# for rx in range(sh.nrows):
#     print sh.row(rx)

#!/usr/bin/python
#coding=utf-8

import wx
from wx.lib.mixins.listctrl import ColumnSorterMixin
from wx.lib.mixins.listctrl import TextEditMixin
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
 
actresses = {
1 : ['jessica alba', 'pomona', '1981'],
2 : ['sigourney weaver', 'new york', '1949'],
3 : ['angelina jolie', 'los angeles', '1975'],
4 : ['natalie portman', 'jerusalem', '1981'],
5 : ['rachel weiss', 'london', '1971'],
6 : ['scarlett johansson', 'new york', '1984']
}
 
 
class SortedListCtrl(wx.ListCtrl,
             ColumnSorterMixin,
             ListCtrlAutoWidthMixin,
             TextEditMixin):
 
     def __init__(self, parent):
         wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL)
         ColumnSorterMixin.__init__(self, -1)
         ListCtrlAutoWidthMixin.__init__(self)
         TextEditMixin.__init__(self)
 
     def GetListCtrl(self):
         return self
 
     def OnGetItemText(self, item, col):
         # Lee el valor a mostrar en mddo LC_VIRTUAL desde el diccionario de datos
         return self.itemDataMap[self.itemIndexMap[item]][col]
 
     def SetVirtualData(self, item, col, text):
         # Guarda el valor editado al diccionario de datos
         self.itemDataMap[self.itemIndexMap[item]][col] = text
 
     def SortItems(self,sorter=cmp):
         # Ajusta el indice de columnas al nuevo ordenamiento
         items = list(self.itemDataMap.keys())
         items.sort(sorter)
         self.itemIndexMap = items
         self.Refresh()
 
 
class Actresses(wx.Frame):
     def __init__(self, parent, id, title):
         wx.Frame.__init__(self, parent, id, title, size=(380, 230))
 
         hbox = wx.BoxSizer(wx.HORIZONTAL)
 
         panel = wx.Panel(self, -1)
 
         self.list = SortedListCtrl(panel)
 
         # Definicion de Columnas ListCtrl
         self.list.InsertColumn(0, 'name', width=140)
         self.list.InsertColumn(1, 'place', width=130)
         self.list.InsertColumn(2, 'year', wx.LIST_FORMAT_RIGHT, 90)
 
         self.list.SetItemCount(len(actresses))
 
         # Valores para ColumnSorterMixin
         self.list.itemDataMap = actresses
         self.list.itemIndexMap = actresses.keys()
         self.list.SetColumnCount(self.list.GetColumnCount())
         self.list.SortListItems(0, 1)
 
         hbox.Add(self.list, 1, wx.EXPAND)
         panel.SetSizer(hbox)
 
         self.Centre()
 
app = wx.PySimpleApp()
Actresses(None, -1, 'actresses').Show(True)
app.MainLoop()

# import wx
# class MyApp(wx.App):
#     def OnInit(self):
#         frame = wx.Frame(None, -1, "Hello from wxPython")
# 
#         id=wx.NewId()
#         self.list=wx.ListCtrl(frame,id,style=wx.LC_REPORT|wx.SUNKEN_BORDER)
#         self.list.Show(True)
# 
#         self.list.InsertColumn(0,"Data #1")
#         self.list.InsertColumn(1,"Data #2")
#         self.list.InsertColumn(2,"Data #3")
# 
#         # 0 will insert at the start of the list
#         pos = self.list.InsertStringItem(0,"hello")
#         # add values in the other columns on the same row
#         self.list.SetStringItem(pos,1,"world")
#         self.list.SetStringItem(pos,2,"!")
# 
#         frame.Show(True)
#         self.SetTopWindow(frame)
#         return True
# 
# app = MyApp(0)
# app.MainLoop()
